package com.bejoy.controller;

import com.bejoy.common.AjaxResult;
import com.bejoy.domain.dto.TUserDTO;
import com.bejoy.domain.model.TUser;
import com.bejoy.service.TUserService;
import com.bejoy.util.StringUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/TUser")
public class TUserController {

    @Autowired
    private TUserService tUserService;

    @PostMapping("/loginUser")
    public AjaxResult loginUser(@RequestBody TUserDTO userDTO){

        if (StringUtils.isEmpty(userDTO.getUsername())) {
            throw new RuntimeException("账号不能为空！");
        }

        if (StringUtils.isEmpty(userDTO.getPassword())) {
            throw new RuntimeException("密码不能为空！");
        }

        return tUserService.loginUser(userDTO);
    }


    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo(Authentication authentication){
        TUser tUser = (TUser) authentication.getPrincipal();

        return AjaxResult.success(tUser);
    }


}
